package com.nf.web;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.nf.entity.ProductEntity;
import com.nf.service.ProductServiceImpl;

@WebServlet("/product/list")
public class ProductListServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		ProductServiceImpl productService=new ProductServiceImpl();
		List<ProductEntity> list=null;
		try {
			list = productService.getAlls();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		ObjectMapper mapper=new ObjectMapper();
		String jsonList=mapper.writeValueAsString(list);
		
		resp.setContentType("application/json;charset=UTF-8");
		resp.getWriter().println(jsonList);
	}

}






